package cn.com.egova.materialdesignexample.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import cn.com.egova.materialdesignexample.R;

public class CollapsingToolbarLayoutActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        setContentView(R.layout.activity_collapsing_toolbar_layout);

        initToolbar();

        initView();
    }

    private void initView() {
        CollapsingToolbarLayout layout = (CollapsingToolbarLayout) findViewById(R.id.collapsingToolbarLayout);
        layout.setTitle("CollapsingToolbarLayout");
        layout.setCollapsedTitleGravity(Gravity.LEFT);
        layout.setExpandedTitleGravity(Gravity.CENTER);
        layout.setExpandedTitleColor(Color.RED);
        layout.setCollapsedTitleTextColor(Color.GREEN);

        TextView tvContnet = (TextView) findViewById(R.id.tv_content);
        String content = "";
        for(int i=0;i<100;i++){
            content += "我爱我的家";
        }
        tvContnet.setText(content);
    }

    private void initToolbar() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        if(toolbar!=null){
            setSupportActionBar(toolbar);
//            toolbar.setTitle("CollapsingToolbarLayout");   //title设置给它已经不管用了.
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//            toolbar.setNavigationIcon(R.mipmap.icon_back);  //如果不设置则会显示默认的返回图标.
            toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onBackPressed();
                }
            });
        }
    }
}
